/**
 * Created by gakuin on 5/23/16.
 */
import React, { Component } from 'react';
import Slider from 'react-slick'

export default class Banner extends Component{
    constructor(props){
        super(props);
        this._goBannerUrl=this.goBannerUrl.bind(this)
    }
    goBannerUrl(url) {
        return function(){
            window.location.href = url;
        }
    }

    shouldComponentUpdate(nextProps, nextState){
        //console.log(this.props.data,"banner shold update?",nextProps,nextState);
        if(this.props.data.length==0){
            console.log('banner update');
            return true;
        }else{
            return false;
        }
    }
    renderbannerlist() {

        return this.props.data.map((banner, index)=> {
            return (
            <img src={banner.pic_url}   style={{height:"125"}} key={"banner"+index} onClick={this._goBannerUrl(banner.banner_url)} />
            )
        })

    }
    render(){
        var settings = {
            dots: false,
            autoplay:true,
            arrows:false
        }

        return(
        <div className='sliderContainer' style={{height:"125",overflow:"hidden"}}>
            <Slider {...settings}>
                {this.renderbannerlist()}
            </Slider>
        </div>
        )
    }
}

Banner.defaultProps = {

}

Banner.propTypes = {

}

